package com.example.softwareconfigurationcoursedesign;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

// 查找商品
@WebServlet("/searchProduct")
public class SearchProductServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Get the search keyword from the request parameters
        String searchKeyword = request.getParameter("searchKeyword");

        // Use the search keyword to retrieve relevant product information from the database
        ProductService productService = new ProductService();
        List<Product> productList = productService.searchProduct(searchKeyword);

        // Set the retrieved product information as a request attribute
        request.setAttribute("productList", productList);

        // Forward the request to a JSP page for displaying the search results
        request.getRequestDispatcher("productSearchResult.jsp").forward(request, response);
    }
}

